<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学员姓名"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学号" prop="studentNo">
        <el-input
          v-model="queryParams.studentNo"
          placeholder="请输入学号"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入班级"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="宿舍栋号" prop="buildingNo">
        <el-select
          v-model="queryParams.buildingNo"
          placeholder="宿舍栋号"
          clearable
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="dict in buildingNoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="楼层" prop="storey">
        <el-select
          v-model="queryParams.storey"
          placeholder="宿舍楼层"
          clearable
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="dict in storeyOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="宿舍号" prop="dormitoryNo">
        <el-input
          v-model="queryParams.dormitoryNo"
          placeholder="请输入宿舍号"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="学员状态"
          clearable
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否毕业" prop="isGraduated">
        <el-select
          v-model="queryParams.isGraduated"
          placeholder="毕业状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in isGraduatedOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basedata:bstudent:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['basedata:bstudent:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-office-building"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['basedata:bstudent:remove']"
        >毕业</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-star-off"
          size="mini"
          :disabled="multiple"
          @click="handleAssignClass"
        >分班</el-button>
      </el-col>
      <el-col :span="1.5">
        <!-- <el-button
          type="warning"
          icon="el-icon-star-on"
          size="mini"
          :disabled="multiple"
          @click="handleAssignDorm"
        >分宿舍</el-button>-->
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="handleImport">寄宿学生导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="handleImport1">走读学生导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="handleImportUpdate">导入更新</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-refresh" size="mini" @click="handleResetPwd">重置密码</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="bstudentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="studentName" :show-overflow-tooltip="true" />
      <el-table-column label="学号" align="center" prop="studentNo" :show-overflow-tooltip="true" />
      <el-table-column label="班级" align="center" prop="className" :show-overflow-tooltip="true" />
      <el-table-column label="人脸照片" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div>
            <label v-if="!scope.row.stuPhoto">
              <el-tag type="danger">无</el-tag>
            </label>
            <label v-if="scope.row.stuPhoto">
              <el-popover
                placement="top"
                :title="scope.row.studentName"
                @show="onShowPic(scope.row)"
                trigger="hover" >
                <image-preview v-if="showPics[scope.row.id]" :src="scope.row.stuPhoto"/>
                <el-tag slot="reference">有</el-tag>
              </el-popover>
            </label>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" width="120" />
      <el-table-column label="性别" align="center" prop="sex" :formatter="sexFormat" />
      <!-- <el-table-column label="年龄" align="center" prop="age" :show-overflow-tooltip="true" /> -->
      <!-- <el-table-column label="家长姓名" align="center" prop="parentName" :show-overflow-tooltip="true" /> -->
      <el-table-column
        label="家长电话"
        align="center"
        prop="parentPhone"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="宿舍栋号" align="center" prop="buildingNo" :formatter="buildingNoFormat" />
      <el-table-column label="楼层" align="center" prop="storey" :formatter="storeyFormat" />
      <el-table-column label="宿舍号" align="center" prop="dormitoryNo" :show-overflow-tooltip="true" />
      <el-table-column label="床位号" align="center" prop="bedNo" :show-overflow-tooltip="true" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="修改时间" align="center" prop="modifyTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime) }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="毕业状态" align="center">
        <template slot-scope="scope">{{ scope.row.isGraduated == '0' ?'在读':'已毕业' }}</template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            active-value="1"
            inactive-value="0"
            @change="handleStatusChange(scope.row)"
            v-if="scope.row.isGraduated == '0'"
          />
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="查看学员信息">
            <el-button
              size="mini"
              circle
              type="info"
              icon="el-icon-view"
              @click="handleView(scope.row, scope.index)"
              v-hasPermi="['basedata:bstudent:query']"
            />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="修改学员信息">
            <el-button
              size="mini"
              circle
              type="success"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['basedata:bstudent:edit']"
              v-if="scope.row.isGraduated == '0'"
            />
          </el-tooltip>
          <!-- <el-tooltip class="item" effect="dark" content="分配宿舍床位">
            <el-button
              size="mini"
              circle
              type="warning"
              icon="el-icon-school"
              @click="HandleAllocation(scope.row)"
              v-hasPermi="['basedata:bstudent:edit']"
              v-if="scope.row.isGraduated == '0'"
            />
          </el-tooltip>-->
          <el-tooltip class="item" effect="dark" content="毕业">
            <el-button
              size="mini"
              circle
              type="danger"
              icon="el-icon-office-building"
              @click="handleDelete(scope.row)"
              v-hasPermi="['basedata:bstudent:remove']"
              v-if="scope.row.isGraduated == '0'"
            />
          </el-tooltip>
          <el-tooltip class="item" effect="dark"
                      :content="scope.row.stuPhoto ? '修改人脸信息' : '添加人脸信息'" placement="top">
            <el-button type="primary" icon="el-icon-camera-solid" size="mini" circle
                       @click="showAddFaceInfo(scope.row)"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="同步到门禁" placement="top">
            <el-button type="primary" icon="el-icon-upload" size="mini"
                       :disabled="!scope.row.stuPhoto" circle
                       @click="syncToAccessControl(scope.row)"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="同步到考勤" placement="top">
            <el-button type="primary" icon="el-icon-upload" size="mini"
                       :disabled="!scope.row.stuPhoto" circle
                       @click="syncToAttendance(scope.row)"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="恢复">
            <el-button
              size="mini"
              circle
              type="primary"
              icon="el-icon-refresh-left"
              @click="handleRestore(scope.row)"
              v-if="scope.row.isGraduated == '1'"
            />
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <FaceRecord
      @onTakePhotoSuccess="onTakePhotoSuccess"
      :visible.sync="addFaceVisible"
      :items="recordFacePerson"/>

    <!-- 学员详细信息 -->
    <el-dialog title="学员详细信息" :visible.sync="open1" width="700px">
      <el-form ref="form" :model="form" label-width="140px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名：">{{ form.studentName }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学号：">{{ form.studentNo }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级：">{{ form.className }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码：">{{ form.phone }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别：">{{ sexFormat(form) }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年龄：">{{ form.age }}</el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="宿舍栋号：">
              {{
              buildingNoFormat(form)
              }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="宿舍楼层：">
              {{
              storeyFormat(form)
              }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="宿舍号：">{{ form.dormitoryNo }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态：">{{ statusFormat(form) }}</el-form-item>
          </el-col>
          <!-- <el-col :span="24">
            <el-form-item label="家长描述信息：">{{form.parentDesc}}</el-form-item>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="学员照片：">
              <img width="100" height="100" :src="form.stuPhoto" alt />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open1 = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="650px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="11">
            <el-form-item label="姓名" prop="studentName">
              <el-input v-model="form.studentName" placeholder="请输入学员姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="学号" prop="studentNo">
              <el-input v-model="form.studentNo" placeholder="请输入学号" :disabled="disabledInput" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="班级" prop="classId">
              <el-select clearable filterable v-model="form.classId" placeholder="请选择">
                <el-option
                  v-for="item1 in classOptions"
                  :key="item1.id"
                  :label="item1.className"
                  :value="item1.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="手机号码" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号码" maxlength="11" />
            </el-form-item>
          </el-col>
          <!--     <el-col :span="11">
              <el-form-item label="身份证号" prop="idcard">
                <el-input v-model="form.idcard" placeholder="请输入身份证号" />
              </el-form-item>
          </el-col>-->
          <el-col :span="11">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择">
                <el-option
                  v-for="dict in sexOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="年龄" prop="age">
              <el-input v-model="form.age" placeholder="请输入年龄" maxlength="3" />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="家长姓名" prop="parentName">
              <el-input v-model="form.parentName" placeholder="请输入家长姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="家长电话" prop="parentPhone">
              <el-input v-model="form.parentPhone" placeholder="请输入家长电话" />
            </el-form-item>
          </el-col>

          <!-- <el-col :span="11">
            <el-form-item label="宿舍栋号" prop="buildingNo">
              <el-select v-model="form.buildingNo" placeholder="宿舍栋号" clearable @change="change1">
                <el-option
                  v-for="dict in buildingNoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="宿舍楼层" prop="storey">
              <el-select v-model="form.storey" placeholder="楼层" clearable @change="change2">
                <el-option
                  v-for="dict in storeyOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">-->
          <!-- <el-form-item label="宿舍号" prop="bdormitoryId">
             <el-select v-model="form.bdormitoryId"  placeholder="请选择">
               <el-option
                       v-for="item in bdormitoryOptions"
                       :key="item.id"
                       :label="`${item.buildingNo}-${item.storey}-${item.dormitoryNo}`"
                       :value="item.id"
               />
             </el-select>
          </el-form-item>-->

          <!-- <el-form-item label="宿舍号" prop="bdormitoryId">
              <el-select v-model="form.bdormitoryId" value-key="id" placeholder="请选择">
                <el-option
                  v-for="item in bdormitoryOptions"
                  :key="item.id"
                  :label="item.dormitoryNo"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-col :span="1.5">
            <el-form-item label="选择宿舍">
              <el-select
                v-model="form.bdormitoryId"
                clearable
                filterable
                placeholder="选择宿舍"
                @change="findDormitoryBedList"
              >
                <el-option
                  v-for="item in bdormitoryListAll"
                  :key="item.bdormitoryId"
                  :value="item.bdormitoryId"
                  :label="item.buildingNo + '-' + item.dormitoryNo"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="选择床位">
              <el-select
                v-model="form.bedId"
                placeholder="选择床位"
                @change="checkBed"
                clearable
                filterable
              >
                <el-option
                  v-for="item in bedList"
                  :key="item.id"
                  :value="item.id"
                  :label="item.bedNo"
                  :disabled="item.studentId"
                >
                  <span style="float: left">{{ '床位编号：' + item.bedNo }}</span>
                  <span
                    style="float: right; color: #8492a6; font-size: 13px"
                    v-if="item.bedType==1"
                  >上铺</span>
                  <span
                    style="float: right; color: #8492a6; font-size: 13px"
                    v-if="item.bedType==2"
                  >下铺</span>
                  <span
                    style="float: right; color: #8492a6; font-size: 13px"
                    v-if="item.bedType==3"
                  >上铺下桌</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <!-- <el-col :span="1.5">
            <el-form-item label="选择宿舍">
              <el-select
                v-model="form.dormitoryId"
                clearable
                filterable
                placeholder="选择宿舍"
                @change="findDormitoryBedList"
              >
                <el-option
                  v-for="item in bdormitoryListAll"
                  :key="item.bdormitoryId"
                  :value="item.bdormitoryId"
                  :label="item.buildingNo + '-' + item.dormitoryNo"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-col :span="1.5">
              <el-form-item label="选择床位">
                <el-select
                  v-model="form.bedId"
                  placeholder="选择床位"
                  @change="checkBed"
                  clearable
                  filterable
                >
                  <el-option
                    v-for="item in bedList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.bedNo"
                  >
                    <span style="float: left">{{ '床位编号：' + item.bedNo }}</span>
                    <span
                      style="float: right; color: #8492a6; font-size: 13px"
                      v-if="item.bedType==1"
                    >上铺</span>
                    <span
                      style="float: right; color: #8492a6; font-size: 13px"
                      v-if="item.bedType==2"
                    >下铺</span>
                    <span
                      style="float: right; color: #8492a6; font-size: 13px"
                      v-if="item.bedType==3"
                    >上铺下桌</span>
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>-->
          <!-- 新 -->
          <!-- <el-form-item label="学生照片:" prop="stuPhoto">
              <el-upload
                border
                class="avatar-uploader"
                :action="activeUrl"
                :headers="headers"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img
                  v-if="form.stuPhoto"
                  :src="form.stuPhoto"
                  class="avatar"
                />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
          </el-form-item>-->
          <!-- 旧 -->
          <!-- <el-form-item label="学员照片">
				   <el-upload
						   ref="upload"
						    :action="activeUrl"
								:data="form"
								:auto-upload="false"
								multiple="multiple"
								:on-change="uploadChange"
						   name="upload"
						   list-type="picture"
						   :limit="1"
						   :file-list="fileList"
						   :on-exceed="onExceed"
               :headers="headers"
						   :before-upload="beforeUpload"
						   :on-preview="handlePreview"
						   :on-success="handleSuccess"
						   :on-remove="handleRemove">
					   <i class="el-icon-plus"></i>
				   </el-upload>

            <el-input v-model="form.photo" type="hidden" />
          </el-form-item>-->
          <!-- </el-col> -->
        </el-row>

        <!-- <el-row>
          <el-col :span="1.5" v-if="dialogVisible">
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
          </el-col>
          <el-col :span="1.5" v-if="dialogVisible">
            <img width="100" height="100" :src="dialogImageUrl" alt="">
          </el-col>
        </el-row>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--  寄宿学员信息导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open3" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        multiple="multiple"
        name="upload"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="info" style="font-size: 12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open3 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!--  在读学员信息导入对话框 -->
    <el-dialog :title="upload1.title" :visible.sync="upload1.open4" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        multiple="multiple"
        name="upload"
        accept=".xlsx, .xls"
        :headers="upload1.headers"
        :action="upload1.url"
        :disabled="upload1.isUploading"
        :on-progress="handleFileUploadProgress1"
        :on-success="handleFileSuccess1"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="info" style="font-size: 12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload1.open4 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!--  学员信息导入更新对话框 -->
    <el-dialog :title="uploadUpdate.title" :visible.sync="uploadUpdate.open" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        multiple="multiple"
        name="upload"
        accept=".xlsx, .xls"
        :headers="uploadUpdate.headers"
        :action="uploadUpdate.url"
        :disabled="uploadUpdate.isUploading"
        :on-progress="handleFileUploadProgressUpdate"
        :on-success="handleFileSuccessUpdate"
        :auto-upload="false"
        :file-list="fileList"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="info" style="font-size: 12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="uploadUpdate.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 分班 -->
    <el-dialog title="分班" :visible.sync="assignClassDialog" width="35%">
      <el-form :model="assignClassForm" ref="assignClassForm" label-width="90px">
        <el-form-item label="待分配学生" prop="ids">
          <el-checkbox-group v-model="assignClassForm.ids">
            <el-checkbox
              v-for="student in studentOptions"
              :label="student.id"
              :key="student.id"
            >{{ student.studentName }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="班级" prop="classId">
          <el-select v-model="assignClassForm.classId" placeholder="请选择">
            <el-option
              v-for="item1 in classOptions"
              :key="item1.id"
              :label="item1.className"
              :value="item1.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAssignClassForm">确 定</el-button>
        <el-button @click="assignClassDialog = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 分宿舍 -->
    <el-dialog title="分宿舍" :visible.sync="assignDormDialog" width="35%">
      <el-form :model="assignDormForm" ref="assignDormForm" label-width="90px">
        <el-form-item label="待分配学生" prop="ids">
          <el-checkbox-group v-model="assignDormForm.ids">
            <el-checkbox
              v-for="student in studentOptions"
              :label="student.id"
              :key="student.id"
              checked
            >{{ student.studentName }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="宿舍栋号" prop="buildingNo">
          <el-select
            v-model="assignDormForm.buildingNo"
            placeholder="请选择宿舍栋号"
            clearable
            size="small"
            @change="change3"
          >
            <el-option
              v-for="dict in buildingNoOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="楼层">
          <el-select
            v-model="assignDormForm.storey"
            placeholder="请选择宿舍楼层"
            clearable
            size="small"
            @change="change4"
          >
            <el-option
              v-for="dict in storeyOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="宿舍号">
          <el-select
            v-model="assignDormForm.bdormitoryId"
            placeholder="请选择宿舍号"
            clearable
            size="small"
          >
            <el-option
              v-for="item in bdormitoryOptions"
              :key="item.id"
              :label="item.dormitoryNo"
              :value="item.id + '-' + item.dormitoryNo"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAssignDormForm">确 定</el-button>
        <el-button @click="assignDormDialog = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 宿舍分配dialog -->
    <el-dialog title="宿舍分配" :visible.sync="dormitoryVisible" width="30%">
      <el-form :model="bedForm" ref="bedForm" class="demo-form-inline" :disabled="false">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名">{{ bedForm.studentName }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级">{{ bedForm.className }}</el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="选择宿舍">
          <el-select
            v-model="bedForm.bdormitoryId"
            clearable
            filterable
            placeholder="选择宿舍"
            @change="findDormitoryBedList"
          >
            <el-option
              v-for="item in bdormitoryListAll"
              :key="item.bdormitoryId"
              :value="item.bdormitoryId"
              :label="item.buildingNo + '-' + item.dormitoryNo"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择床位">
          <el-select
            v-model="bedForm.bedId"
            placeholder="选择床位"
            @change="checkBed"
            clearable
            filterable
          >
            <el-option
              disabled
              v-for="item in bedList"
              :key="item.id"
              :value="item.id"
              :label="item.bedNo"
            >
              <span style="float: left">{{ '床位编号：' + item.bedNo }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.bedType==1">上铺</span>
              <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.bedType==2">下铺</span>
              <span
                style="float: right; color: #8492a6; font-size: 13px"
                v-if="item.bedType==3"
              >上铺下桌</span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBed">确 定</el-button>
        <el-button @click="cancelBed">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  restoreStudent,
  listBStudent,
  getBStudent,
  addBStudent,
  updateBStudent,
  delBStudent,
  exportBStudent,
  changeBStudentStatus,
  importTemplate,
  assignClass,
  assignDrom,
  getBdormitoryListAll,
  getDormitoryBedList,
  allocateDormitoryAndBed,
  submitDormitoryAndBed, resetPwd, syncPhotoToAccessControl, syncPhotoToAttendance
} from "@/api/basedata/bstudent";
import { listAllBClass } from "@/api/basedata/bclass";
import { getBDormitoryListByCol } from "@/api/basedata/bdormitory";
import { getToken } from "@/utils/auth";
import FaceRecord from "@/components/FaceRecord/index.vue";

const cityOptions = ["上海", "北京", "广州", "深圳"];
export default {
  name: "BStudent",
  components: {FaceRecord},
  computed: {
    headers() {
      return {
        //'Content-Type': 'multipart/form-data',
        Authorization: "Bearer " + getToken()
      };
    }
  },
  data() {
    return {
      showPics: {},
      recordFacePerson: [],
      addFaceVisible: false,
      bedList: [],
      // 宿舍床号分配
      bedForm: {
        className: "",
        studentName: "",
        bedId: "",
        dormitoryId: ""
      },
      // 宿舍分配的dialog
      dormitoryVisible: false,
      //上传的路径
      activeUrl: "",
      imgPath: process.env.VUE_APP_BASE_API + "/student/image/",
      //判断是否上传文件
      isHaveFile: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中学生姓名
      studetnNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 字典表格数据
      bstudentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详情弹出层
      open1: false,
      studentOptions: [],
      // 班级
      classOptions: [],
      // 性别状态字典
      sexOptions: [],
      // 宿舍栋号
      buildingNoOptions: [],
      // 楼层
      storeyOptions: [],
      // 宿舍号
      bdormitoryOptions: [],
      assignDormDialog: false,
      assignClassDialog: false,
      buildingNo: undefined,
      storey: undefined,
      bdormitoryId: undefined,

      fileList: [],
      photo: "",
      disabledInput: false,

      // 状态数据字典
      statusOptions: [],
      isGraduatedOptions: [
        {
          dictValue: 0,
          dictLabel: "在读"
        },
        {
          dictValue: 1,
          dictLabel: "已毕业"
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: undefined,
        studentNo: undefined,
        className: undefined,
        buildingNo: undefined,
        storey: undefined,
        dormitoryNo: undefined,
        status: undefined,
        isGraduated: undefined
      },
      //寄宿学员信息导入参数
      upload: {
        // 是否显示弹出层（学员信息导入）
        open3: false,
        // 弹出层标题（学员信息导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的学员信息数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/basedata/bstudent/importData"
      },
      //在读学员信息导入参数
      upload1: {
        // 是否显示弹出层（学员信息导入）
        open4: false,
        // 弹出层标题（学员信息导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的学员信息数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/basedata/bstudent/importData1"
      },

      //导入更新
      uploadUpdate: {
        // 是否显示弹出层（学员信息导入）
        open: false,
        // 弹出层标题（学员信息导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的学员信息数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url:
          process.env.VUE_APP_BASE_API + "/basedata/bstudent/importExamResult"
      },
      // 表单参数
      form: {},
      dialogImageUrl: "",
      dialogImageUrl1: "",
      // dialogVisible: false,
      //分配宿舍表单参数
      assignDormForm: {},
      //分配班级表单参数
      assignClassForm: {},
      bdormitoryListAll: [],
      // 表单校验
      rules: {
        studentName: [
          { required: true, message: "学员姓名不能为空", trigger: "blur" }
        ],
        studentNo: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        classId: [{ required: true, message: "班级不能为空", trigger: "blur" }],
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        sex: [{ required: true, message: "性别不能为空", trigger: "blur" }],
        idcard: [
          //{ required: true, message: "身份证号不能为空", trigger: "blur" },
          {
            pattern: /^\d{17}(\d|x)$/,
            message: "你输入的身份证长度或格式错误",
            trigger: "blur"
          }
        ],
        // parentName: [
        //   { required: true, message: "家长姓名不能为空", trigger: "blur" }
        // ],
        parentPhone: [
          { required: true, message: "家长电话不能为空", trigger: "blur" }
        ]
        // buildingNo: [
        //   { required: true, message: "第几栋不能为空", trigger: "blur" }
        // ],
        // storey: [
        //   { required: true, message: "楼层不能为空", trigger: "blur" }
        // ],
        // bdormitoryId: [
        //   { required: true, message: "宿舍号不能为空", trigger: "blur" }
        // ],
        // photo: [
        //   { required: true, message: '请上传学员照片' }
        // ]
      }
    };
  },
  created() {
    this.getBdormitoryListAll();
    this.getList();
    this.listAllBClass();
    this.getDicts("sys_building").then(response => {
      this.buildingNoOptions = response.data;
    });
    this.getDicts("sys_storey").then(response => {
      this.storeyOptions = response.data;
    });
    this.getDicts("sys_student_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    // this.form.bdormitoryId = this.bdormitoryOptions[0].id ;
    this.activeUrl =
      process.env.VUE_APP_BASE_API + "/basedata/bstudent/uploadImage";
  },
  methods: {
    onShowPic(row){
      this.$delete(this.showPics,row.id);
      this.$set(this.showPics,row.id,true);
    },
    appendShowPicAttr(dataList){
      if(!dataList){
        return;
      }
      dataList.forEach(item => {
        this.showPics[item.id] = false;
      });
    },
    onTakePhotoSuccess() {
      this.getList();
    },
    showAddFaceInfo(row) {
      this.recordFacePerson = [{
        "name": row.studentName,
        "id": row.id,
        "className": row.className
      }];
      this.addFaceVisible = true;
    },
    syncToAccessControl(row){
      syncPhotoToAccessControl(row).then(res => {
        if(res.code === 200){
          this.$message.success("同步人脸到门禁设备成功");
        }else {
          let msg = "同步失败";
          if(res.message && res.message.length > 0){
            msg += "," + res.message;
          }
          this.$message.error(msg);
        }
      })
    },
    syncToAttendance(row){
      syncPhotoToAttendance(row).then(res=>{
        if(res.code === 200){
          this.$message.success("同步人脸到考勤设备成功");
        }else {
          let msg = "同步失败";
          if(res.message && res.message.length > 0){
            msg += "," + res.message;
          }
          this.$message.error(msg);
        }
      });
    },
    checkBed(e) {
      console.log(e);
    },
    bedReset() {
      this.bedList = [];
      this.bedForm = {
        className: "",
        studentName: "",
        bedId: "",
        dormitoryId: ""
      };
    },
    // 床位取消
    cancelBed() {
      this.dormitoryVisible = false;
      this.bedReset();
    },
    // 床位提交
    submitBed() {
      let obj = {
        studentId: this.studentId,
        dormitoryId: this.bedForm.dormitoryId,
        bedId: this.bedForm.bedId
      };
      console.log(obj);
      submitDormitoryAndBed(obj).then(res => {
        if (res.code == 200) {
          this.msgSuccess("分配成功");
          this.dormitoryVisible = false;
          this.bedReset();
          this.getList();
        }
      });
    },
    // 选择宿舍获取床位
    findDormitoryBedList(e) {
      this.form.bedId = "";
      this.bedList = [];
      if (e) {
        getDormitoryBedList(e).then(res => {
          this.bedList = res.data;
          // console.log(this.bedList)
        });
      }
    },
    // 获取宿舍列表
    getBdormitoryListAll() {
      getBdormitoryListAll().then(res => {
        this.bdormitoryListAll = res.data;
      });
    },
    // 分配床位
    HandleAllocation(row) {
      // this.bedForm.dormitoryId = row.bdormitoryId;
      this.studentId = row.id;
      this.dormitoryVisible = true;
      this.bedForm.className = row.className;
      this.bedForm.studentName = row.studentName;
    },
    //分宿舍
    handleAssignDorm() {
      this.assignDormForm = {
        buildingNo: undefined,
        storey: undefined,
        bdormitoryId: undefined,
        ids: []
      };
      this.assignDormDialog = true;
    },
    //分班
    handleAssignClass() {
      this.assignClassForm = {
        classId: undefined,
        ids: []
      };
      this.assignClassDialog = true;
    },
    //分班提交
    submitAssignClassForm() {
      assignClass(this.assignClassForm).then(response => {
        if ((response.code = 200)) {
          this.msgSuccess(response.data);
          this.assignClassDialog = false;
          this.studentOptions = [];
          this.getList();
        } else {
          this.msgError(response.data);
        }
      });
    },
    //分宿舍提交
    submitAssignDormForm() {
      assignDrom(this.assignDormForm).then(response => {
        if ((response.code = 200)) {
          this.msgSuccess(response.data);
          this.assignDormDialog = false;
          this.studentOptions = [];
          this.getList();
        } else {
          this.msgError(response.data);
        }
      });
    },
    //文件状态改变
    // uploadChange: function (file, fileList) {
    //   if (fileList.length > 0) {
    //     this.isHaveFile = true;
    //   } else {
    //     this.isHaveFile = false;
    //   }
    // },

    // closeDialog: function (done) {
    //   this.$refs.upload.clearFiles();
    //   this.open = false;
    //   this.reset();
    // },

    change1() {
      this.bdormitoryOptions = [];
      //this.form.bdormitoryId='';

      // 获取栋号
      let buildingNo_dictValue = this.buildingNoOptions.find(
        val => val.dictValue == this.form.buildingNo
      ).dictValue;

      // 获取楼层号
      let storey_dictValue = this.storeyOptions.find(
        val => val.dictValue == this.form.storey
      ).dictValue;
      if (storey_dictValue == undefined) {
        alert("楼层号为空");
        return;
      }

      getBDormitoryListByCol(buildingNo_dictValue, storey_dictValue).then(
        response => {
          this.bdormitoryOptions = response.data;
          //  console.log(this.bdormitoryOptions);
          // alert(this.bdormitoryOptions)
        }
      );
    },
    change2() {
      this.bdormitoryOptions = [];

      // 获取栋号
      let buildingNo_dictValue = this.buildingNoOptions.find(
        val => val.dictValue == this.form.buildingNo
      ).dictValue;

      // 获取楼层号
      let storey_dictValue = this.storeyOptions.find(
        val => val.dictValue == this.form.storey
      ).dictValue;
      if (buildingNo_dictValue == undefined) {
        return;
      }

      // 清空宿舍号
      this.$set(this.form, "bdormitoryId", "");

      getBDormitoryListByCol(buildingNo_dictValue, storey_dictValue).then(
        response => {
          this.bdormitoryOptions = response.data;
          if (this.bdormitoryOptions.length < 1) {
            this.form.bdormitoryId = "";
          }
        }
      );
    },
    change3() {
      //置空宿舍号
      this.bdormitoryOptions = [];
      // 获取栋号
      let buildingNo_dictValue = this.buildingNoOptions.find(
        val => val.dictValue == this.assignDormForm.buildingNo
      ).dictValue;
      // 获取楼层号
      let storey_dictValue = this.storeyOptions.find(
        val => val.dictValue == this.assignDormForm.storey
      ).dictValue;
      if (storey_dictValue == undefined) {
        alert("楼层号为空");
        return;
      }
      this.$set(this.assignDormForm, "bdormitoryId", "");
      getBDormitoryListByCol(buildingNo_dictValue, storey_dictValue).then(
        response => {
          this.bdormitoryOptions = response.data;
        }
      );
    },
    change4() {
      this.bdormitoryOptions = [];
      // 获取栋号
      let buildingNo_dictValue = this.buildingNoOptions.find(
        val => val.dictValue == this.assignDormForm.buildingNo
      ).dictValue;
      // 获取楼层号
      let storey_dictValue = this.storeyOptions.find(
        val => val.dictValue == this.assignDormForm.storey
      ).dictValue;
      if (buildingNo_dictValue == undefined) {
        return;
      }
      // 清空宿舍号
      this.$set(this.assignDormForm, "bdormitoryId", "");
      getBDormitoryListByCol(buildingNo_dictValue, storey_dictValue).then(
        response => {
          this.bdormitoryOptions = response.data;
          if (this.bdormitoryOptions.length < 1) {
            this.assignDormForm.bdormitoryId = "";
          }
        }
      );
    },

    /** 详细按钮操作 */
    handleView(row) {
      this.open1 = true;
      this.form = row;
      // this.dialogImageUrl1 = process.env.VUE_APP_BASE_API +'/basedata/bstudent/getPhoto.do?id=' + this.form.id + '&width=200&height=200';
    },
    //文件上传成功的钩子函数
    // handleSuccess(res, file) {
    //   if (this.form.id !== undefined) {
    //     //alert(res.message);
    //     console.log(res);
    //     if (res.code == 200) {
    //       this.$message({
    //         type: 'info',
    //         message: '操作成功',
    //         duration: 6000
    //       });
    //       //关闭弹出层
    //       this.open = false;
    //       this.getList();
    //       this.$refs.upload.clearFiles();
    //     } else {
    //       this.$message({
    //         type: 'info',
    //         message: '操作失败',
    //         duration: 6000
    //       });

    //     }
    //   }
    //  	this.getList();
    // },
    //删除文件之前的钩子函数
    // handleRemove(file, fileList) {
    // 		this.$message({
    // 		  type: 'info',
    // 			message: '已删除原有图片',
    // 			duration: 6000
    // 			});
    // 			this.isHaveFile = false;
    // },
    //点击列表中已上传的文件事的钩子函数
    // handlePreview(file) {
    // },
    //上传的文件个数超出设定时触发的函数
    // onExceed(files, fileList) {
    // 		this.$message({
    // 		type: 'info',
    // 		message: '最多只能上传一个图片',
    // 		duration: 6000
    // 		});
    //  },
    //文件上传前的前的钩子函数
    //参数是上传的文件，若返回false，或返回Primary且被reject，则停止上传
    // beforeUpload(file) {
    //         const isJPG = file.type === 'image/jpeg';
    //         const isGIF = file.type === 'image/gif';
    //         const isPNG = file.type === 'image/png';
    //         const isBMP = file.type === 'image/bmp';
    //         const isLt2M = file.size / 1024 / 1024 < 2;

    //         if (!isJPG && !isGIF && !isPNG && !isBMP) {
    //               this.$message.error('上传图片必须是JPG/GIF/PNG/BMP 格式!');
    //         }
    //         if (!isLt2M) {
    //               this.$message.error('上传图片大小不能超过 2MB!');
    //          }
    // },

    /** 查询宿舍列表 */
    getList() {
      this.loading = true;
      listBStudent(this.queryParams).then(response => {
        this.bstudentList = response.data.list;
        this.total = response.data.total;
        this.appendShowPicAttr(this.bstudentList);
        this.loading = false;
      });
    },
    listAllBClass() {
      listAllBClass().then(response => {
        this.classOptions = response.data;
      });
    },
    // 字典设备状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    buildingNoFormat(row, column) {
      return this.selectDictLabel(this.buildingNoOptions, row.buildingNo);
    },
    storeyFormat(row, column) {
      return this.selectDictLabel(this.storeyOptions, row.storey);
    },
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    bdormitoryFormat(row, column) {
      return this.selectDictLabel(this.bdormitoryOptions, row.bdormitoryId);
    },
    // 学员状态修改
    handleStatusChange(row) {
      let text = row.status === "1" ? "寄宿" : "走读";
      this.$confirm(
        '确认要将序号为"' + row.id + '"的学员设置为?' + text,
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return changeBStudentStatus(row.id, row.status);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function() {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        studentName: undefined,
        studentNo: undefined,
        classId: undefined,
        className: undefined,
        phone: undefined,
        idcard: undefined,
        sex: undefined,
        age: undefined,
        parentName: undefined,
        parentPhone: undefined,
        buildingNo: undefined,
        storey: undefined,
        dormitoryNo: undefined,
        status: "1"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员信息";
      this.disabledInput = false;

      //新增时隐藏被修改图片
      // this.dialogVisible=false;
      // this.activeUrl = 'http://localhost:9003/basedata/bstudent/createStu';
      // this.activeUrl = process.env.VUE_APP_BASE_API +'/basedata/bstudent/createStu';
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.studentOptions = selection;
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      console.log(row);
      if (row.bdormitoryId) {
        getDormitoryBedList(row.bdormitoryId).then(res => {
          this.bedList = res.data;
        });
      }

      const id = row.id || this.ids;
      getBStudent(id).then(response => {
        console.log(response);
        console.log("response");
        this.form = response.data;
        // this.form.bedId = Number(response.data.bedId);
        this.bedForm.bedId = Number(response.data.bedId);
        console.log(this.bedForm.bedId);
        this.open = true;
        this.title = "修改学员信息";
        //学号新增之后不可修改
        this.disabledInput = true;
        //显示被修改的图片信息
        // this.dialogVisible = true;
        // this.dialogImageUrl = 'http://localhost:9003/basedata/bstudent/getPhoto.do?id=' + this.form.id + '&width=200&height=200';
        // this.dialogImageUrl = process.env.VUE_APP_BASE_API +'/basedata/bstudent/getPhoto.do?id=' + this.form.id + '&width=200&height=200';

        // this.activeUrl = 'http://localhost:9003/basedata/bstudent/updateAndUpload';
        // this.activeUrl = process.env.VUE_APP_BASE_API +'/basedata/bstudent/updateAndUpload';
        getBDormitoryListByCol(this.form.buildingNo, this.form.storey).then(
          response => {
            this.bdormitoryOptions = response.data;
            this.bdormitoryOptions.forEach(a => {
              // a.id = a.id.toString();
              a.id = a.id;
            });
          }
        );
      });
    },
    // uploadSectionFile(param) {
    // 				var form = new FormData();
    // 				if(null !=	param){
    // 				var fileObj = param.file;
    // 					form.append("file", fileObj);
    // 				}
    // },
    /** 提交按钮 */
    /*
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id !== undefined) {
            updateBStudent(this.form.id, this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
          } else {
            addBStudent(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
          }
        }
      });
    },
		*/
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // console.log("stu",this.form)
          if (this.form.id !== undefined) {
            // if (!this.isHaveFile) {
            updateBStudent(this.form.id, this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
            // } else {
            //   //alert('111 进入修改并且有选择了文件.........')
            //   if (this.form.age == undefined) {
            //     this.form.age = "";
            //   }
            //   if (this.form.id == undefined) {
            //     this.form.id = "";
            //   }
            //   if (this.form.sex == undefined) {
            //     this.form.sex = 2;
            //   }
            //   if (this.form.idcard == undefined) {
            //     this.form.idcard = "";
            //   }
            //   /*文件上传，附带表单数据*/
            //   this.$refs.upload.submit();
            // }
          } else {
            //alert("000000 this.form.id ==  undefined , form.id 不存在"+ this.form.id);
            // if (this.isHaveFile) {
            //   // alert('新增学生信息，选择了需要上传的文件.............')
            //   if (this.form.age == undefined) {
            //     this.form.age = "";
            //   }
            //   if (this.form.id == undefined) {
            //     this.form.id = "";
            //   }
            //   if (this.form.sex == undefined) {
            //     this.form.sex = 2;
            //   }
            //   if (this.form.idcard == undefined) {
            //     this.form.idcard = "";
            //   }
            //   /*文件上传，附带表单数据*/
            //   this.$refs.upload.submit();
            // } else {
            //alert('新增学生信息，并且没有选择文件.............')
            addBStudent(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
            // }
            //  else {
            //   alert("请上传学员照片");
            // }
          }
        }
      });
    },

    handleResetPwd(row){
      const ids = row.id || this.ids;
      // console.log(ids);
      this.$confirm(
        '是否重置学员编号为"' + ids + '"的数据项的密码?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return resetPwd(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("重置成功");
        })
        .catch(function() {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      console.log(ids);
      this.$confirm(
        '是否确认学员编号为"' + ids + '"的数据项已经毕业?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delBStudent(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function() {});
    },
    handleRestore(row) {
      const ids = row.id || this.ids;
      console.log(ids);
      this.$confirm(
        '是否确认恢复学员编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return restoreStudent(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("恢复成功");
        })
        .catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有学员数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportBStudent(queryParams);
        })
        .then(response => {
          if (queryParams.className) {
            this.fileDownload(
              response.data,
              queryParams.className + "班学员信息.xlsx"
            );
          } else {
            this.fileDownload(response.data, "学员信息.xlsx");
          }
        })
        .catch(function() {});
    },

    //=================== 文件导入 ================
    // 寄宿导入按钮操作
    handleImport() {
      this.upload.title = "寄宿学员信息导入";
      this.upload.open3 = true;
    },
    // 走读学生导入按钮操作
    handleImport1() {
      this.upload1.title = "走读学员信息导入";
      this.upload1.open4 = true;
    },

    // 学员信息更新导入按钮操作
    handleImportUpdate() {
      this.uploadUpdate.title = "学员信息更新导入";
      this.uploadUpdate.open = true;
    },

    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传中处理
    handleFileUploadProgress1(event, file, fileList) {
      this.upload1.isUploading = true;
    },
    // 导入更新文件上传中处理
    handleFileUploadProgressUpdate(event, file, fileList) {
      this.uploadUpdate.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open3 = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.message, "导入结果", {
        dangerouslyUseHTMLString: true
      });
      this.getList();
    },
    // 文件上传成功处理
    handleFileSuccess1(response, file, fileList) {
      this.upload1.open4 = false;
      this.upload1.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.message, "导入结果", {
        dangerouslyUseHTMLString: true
      });
      this.getList();
    },

    // 更新导入文件上传成功处理
    handleFileSuccessUpdate(response, file, fileList) {
      this.uploadUpdate.open = false;
      this.uploadUpdate.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.message, "导入结果", {
        dangerouslyUseHTMLString: true
      });
      this.getList();
    },
    // 下载模板操作
    importTemplate() {
      importTemplate().then(response => {
        this.fileDownload(response.data, "学员管理模板.xlsx");
      });
    },

    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 提交上传文件
    submitFileForm1() {
      this.$refs.upload1.submit();
    },

    // === 照片上传 ===
    //上传logo成功回调
    handleAvatarSuccess(res, file) {
      this.form.photo = res.result;
    },
    //上传logo前校验
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 10;
      if (!isLt2M) {
        this.$message.error("上传学生照片大小不能超过10MB!");
      }
      return isLt2M;
    }
  }
};
</script>

<style lang='scss' scoped>
::v-deep( .avatar-uploader .el-upload ){
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
</style>
